package com.meng.system.controller.auth;


import com.meng.system.domain.vo.ResponseVO;
import com.meng.system.domain.vo.SysMenuVO;
import com.meng.system.enums.ErrorEnum;
import com.meng.system.service.auth.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 菜单权限表 前端控制器
 *
 * @author: Xu Meng
 * @program: minions-cloud
 * @create: 2021-01-14 23:06
 **/
@Api(tags = "菜单权限表")
@Slf4j
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController {


    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("添加菜单")
    @PostMapping
    public ResponseVO<?> save(@RequestBody SysMenuVO menu) {
        return ResponseVO.result(ErrorEnum.SUCCESS, sysMenuService.save(menu));
    }

    @ApiOperation("获取菜单树")
    @GetMapping
    public ResponseVO<?> findMenuTreeList() {
        return ResponseVO.result(ErrorEnum.SUCCESS, sysMenuService.findMenuTreeList());
    }

    @ApiOperation("修改菜单")
    @PutMapping
    public ResponseVO<?> updateMenu(@RequestBody SysMenuVO sysMenu) {
        return ResponseVO.result(ErrorEnum.SUCCESS, sysMenuService.updateById(sysMenu));
    }

    @ApiOperation("根据id删除菜单")
    @DeleteMapping("/{id}")
    public ResponseVO<?> deleteMenu(@PathVariable("id") Integer id) {
        return ResponseVO.result(ErrorEnum.SUCCESS, sysMenuService.removeById(id));
    }

}

